# 导包
from API.login import LoginAPI

class TestLogin:
    uuid=None
    # 1前置条件
    def setup_method(self):
        # 实例化对象
        self.login_api=LoginAPI()
        res_v=self.login_api.get_verify_code()
        print(res_v.json())
        TestLogin.uuid=res_v.json()["uuid"]
        print(TestLogin.uuid)

    # 2后置条件
    def teardown(self):
        pass
        # 1登陆成功
    def test01_login_success(self):

        test_data={

        "username":"admin",
        "password":"HM_2023_test",
        "code":"2",
        "uuid":TestLogin.uuid
        }
        res_login_success=self.login_api.login(test_data=test_data)
        print(res_login_success.json())

        # 断言响应码为200
        assert res_login_success.status_code==200
        #断言包含"成功二字"
        assert "成功" in res_login_success.text
        #断言响应json的code里面为200
        assert 200==res_login_success.json()["code"]


        # 2 登陆失败(用户名为空)
    def test02_login_fail(self):
        test_data = {

            "username": "",
            "password": "HM_2023_test",
            "code": "2",
            "uuid": TestLogin.uuid
        }
        res_login_fail = self.login_api.login(test_data=test_data)
        print(res_login_fail.json())
        # 断言响应码为200
        assert res_login_fail.status_code == 200
        # 断言包含"成功二字"
        assert "错误" in res_login_fail.text
        # 断言响应json的code里面为200
        assert 500 == res_login_fail.json()["code"]
        #3 登陆失败(用户名为不存在)
    def test03_login_fail(self):
        test_data = {

            "username": "111111777",
            "password": "HM_2023_test",
            "code": "2",
            "uuid": TestLogin.uuid
        }
        res_login_fail = self.login_api.login(test_data=test_data)
        print(res_login_fail.json())
        # 断言响应码为200
        assert res_login_fail.status_code == 200
        # 断言包含"成功二字"
        assert "错误" in res_login_fail.text
        # 断言响应json的code里面为200
        assert 500 == res_login_fail.json()["code"]



